from collections import defaultdict

tmp = """
weibo	?	item_content
zhihu	highlight.title	object.content
xhs	note_card.display_title	?
ks	photo.caption	?
dy	aweme_info.share_info.share_title	aweme_info.share_info.share_desc_info
dingxiang	content	answer
chunyu	item_title	item_content
weiyi	topicTitle	intro
haodaifu	item_title	item_content
"""

platform2text_col = defaultdict(dict)
tmp = {'chunyu': {'content': 'item_content', 'title': 'item_title'},
       'dingxiang': {'content': 'answer', 'title': 'content'},
       'dy': {'content': 'aweme_info.share_info.share_desc_info',
              'title': 'aweme_info.share_info.share_title'},
       'haodaifu': {'content': 'item_content', 'title': 'item_title'},
       'ks': {'content': '?', 'title': 'photo.caption'},
       'weibo': {'content': 'item_content', 'title': '?'},
       'weiyi': {'content': 'intro', 'title': 'topicTitle'},
       'xhs': {'content': '?', 'title': 'note_card.display_title'},
       'zhihu': {'content': 'object.content',
                 'title': 'highlight.title'}}
platform2text_col.update(tmp)
wenzhen = ['dingxiang', 'chunyu', 'weiyi', 'haodaifu']
socialMedia = [e for e in tmp if e not in wenzhen]


def is_wenzhen(platform):
    return platform in wenzhen


print(socialMedia)


# {"item_type" : "wenzhen"} 丁香  有年龄
# {"url_type"  : "wenzhen"} 好大夫
# {"url_type"  : "disease"} 春雨
#  weiyi 没找到

def get_wenzhen_row(c, e):
    if c == 'dingxiang':
        row = [c, e['search_key'],'', '', e['content'], e['answer'], '']
    elif c == 'chunyu':
        # item_title	item_content	问诊总结.问题描述	问诊总结.分析及建议	交流记录

        q = ''
        a = ''
        if '问诊总结' in e:
            q, a = e['问诊总结']['问题描述'], e['问诊总结']['分析及建议']
        row = [c, e['search_key'], e['item_title'], e['item_content'], q, a, e.get('交流记录','')]
    elif c == 'haodaifu':
        # item_title	item_content	病例信息.*	问诊建议.*	交流记录
        q = ''
        a = ''
        if '病例信息' in e:
            for k, v in e['病例信息'].items():
                q += f'{k}:{v}\n'

        if '问诊建议' in e:
            for k, v in e['问诊建议'].items():
                a += f'{k}:{v}\n'
        row = [c, e['search_key'], e['item_title'], e['item_content'], q, a, e.get('交流记录', '')]
    else:
        return []
    return row